<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>权限配置管理</title>
	<#include "./comm/meta-base.ftl" />
	<#include "./comm/meta-easyui.ftl" />
	<#include "./comm/meta-comm.ftl" />
	<link href="${basePath}/static/css/privilege.css" rel="stylesheet" />
</head>
<body>
<div class="easyui-layout" fit="true" >
        <div data-options="region:'west'" style="width:400px;">
        	
        	<div id="datagrid_toolbar">
	            <div class="buttons-preview" >
	                <a class="btn btn-default  btn-sm" 
	                	href="javascript:addPrivilegeGroup()"><i class="fa fa-plus"></i>新增权限组</a>
	                <a class="btn btn-primary btn-sm" 
	                	href="javascript:modifyPrivilegeGroup()"><i class="fa fa-edit"></i> 修改权限组</a>
	                <a class="btn btn-danger btn-sm" 
	                	href="javascript:removePrivilegeGroup()"><i class="fa fa-times"></i>删除</a>
	            </div>
	        </div>
		    <table id="data_table" class="easyui-datagrid"  border="0"  rownumbers="true" fitColumns="true" fit="true"
	               data-options="
	                   url: '${basePath}/privilege-group/privilege-group-list-json',
	                   method: 'get',
	                   rownumbers: true,
	                   idField: 'id',
	                   singleSelect: true,
	                   toolbar:'#datagrid_toolbar',
	                   onLoadSuccess:dataTableSuccess,
	                   onClickRow:dataTableClickRow
	               ">
	           <thead>
	           <tr>
	                <th data-options="field:'name',width:300">权限组名称</th>
	            </tr>
	           </thead>
	       </table>
        	
        </div>
        <div data-options="region:'center'" class="tree_table">
            
            
		    <table id="tree_table" class="easyui-treegrid "  border="0"  rownumbers="true" fitColumns="true" fit="true"
	               data-options="
	               	   url:'${basePath}/privilege-group/privilege-tree-json/${upmsPrivilegeGroupPO.privilegeGroupId}',
	                   method: 'get',
	                   rownumbers: true,
	                   idField: 'id',
	                   lines: true,
	                   checkOnSelect:false,
	                   treeField: 'text'
	               ">
	           <thead>
	           <tr>
	                <th data-options="field:'text',width:300">权限树</th>
	                <th data-options="field:'programCode',width:width(0.2)">程序代码</th>
	                <!--
	                <th data-options="field:'operateJSON',width:width(0.4),formatter:operatePriFormatter">操作权限</th>
	                -->
	            </tr>
	           </thead>
	       </table>
        </div>
    </div>

</body>
</html>
<style>
.tree_table .datagrid-row-selected{background:#fff;color:#000;}
.tree_table .datagrid-cell-c1-operateNodes{overflow:visible !important;} 
.tree_table .datagrid-row-over{background:#fff;}
</style>
<script type="text/javascript">
function removePrivilegeGroup(){
	var row = $('#data_table').datagrid('getSelected');
	var url="${basePath}/privilege-group/privilege-group-remove/"+row.privilegeGroupId;
	bootbox.confirm("你确定要删除"+row.name+"?", function (result) {
    	if (result) {
        	$.post(url,{},function(data){
        		if(data){
        			window.location.reload();
        		}else{
        			Notify(row.name+'已经被使用,不可删除!', 'top-right', '5000', 'danger', 'fa-bolt', true);
        		}
			});
     	}
    });
}

function operatePriFormatter(value,row,index){
	var html="";
	if(''!=value&&null!=value){
		var operateJSON = eval("(" + value + ")"); 
		for(var i=0;i<operateJSON.length;i++){
			var operateObj=operateJSON[i];
			html+="<div value='"+operateObj.operateId+"' class='operateDiv ' >"+operateObj.name+"</div>";
		}
	}
	return html;
}

function addPrivilegeGroup(){
	var url="${basePath}/privilege-group/privilege-group-addin";
	openWindow("新增权限组",url,1000,650,true);
}
function modifyPrivilegeGroup(){
	var row = $('#data_table').datagrid('getSelected');
	var url="${basePath}/privilege-group/privilege-group-modifyin/"+row.privilegeGroupId;
	openWindow("修改权限组",url,1000,650,true);
}


function dataTableClickRow(index,row){
	var url="${basePath}/privilege-group/privilege-tree-json/"+row.privilegeGroupId;
		$.ajax({
			url: url,
			type: "POST",
			dataType:'json',
			success: function (data) {
				$("#tree_table").treegrid('loadData',data);
			}
		});
}
function dataTableSuccess(){
	$('#data_table').datagrid('selectRow',0);
	    var row = $('#data_table').datagrid('getSelected');
		var url="${basePath}/privilege-group/privilege-tree-json/"+row.privilegeGroupId;
		$.ajax({
			url: url,
			type: "POST",
			dataType:'json',
			success: function (data) {
				$("#tree_table").treegrid('loadData',data);
			}
		});

}

$(document).ready(function(){
	
});
</script>


